import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  {
    name: 'Home',
    path: '/',
    meta: {
      title: '这是首页！'
    },
    component: () => import('@/views/Home.vue'),
    redirect: '/use-XYZ-create-map',
    children: [
      {
        name: 'use-XYZ-create-map',
        path: '/use-XYZ-create-map',
        meta: {
          title: 'XYZ实例化地图'
        },
        component: () => import('@/views/pages/UseXYZCreateMap.vue')
      },
      {
        name: 'use-WMTS-create-map',
        path: '/use-WMTS-create-map',
        meta: {
          title: 'WMTS实例化地图'
        },
        component: () => import('@/views/pages/UseWMTSCreateMap.vue')
      },
      {
        name: 'TyphoonPath',
        path: '/typhoonPath',
        meta: {
          title: '台风路径'
        },
        component: () => import('@/views/pages/TyphoonPath.vue')
      },
      {
        name: 'OverView',
        path: '/overview',
        meta: {
          title: '鹰眼视窗'
        },
        component: () => import('@/views/pages/OverView.vue')
      }
    ]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to, from, next) => {
  window.document.title = to.meta.title

  next()
})

export default router
